/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package character_10;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

/**
 *
 * @author Administrator
 */
public class Member2 implements Serializable{
    
    private String number;
    private String name;
    private int age;

    public Member2(String number, String name, int age) {
        this.number = number;
        this.name = name;
        this.age = age;
    }

   @Override
    public String toString(){
        return String .format("(%s,%s,%d)", number,name,age);
    }
    
    public void save() throws IOException{
    
        try (ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream(number)) ){
            output.writeObject(this);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    public static Member2 load(String number) throws IOException,ClassNotFoundException{
    
        Member2 member2;
        try (ObjectInputStream input = new ObjectInputStream(new FileInputStream(number))){
            member2 = (Member2) input.readObject();
        }
        return member2;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getNumber() {
        return number;
    }

    public void setNumber(String number) {
        this.number = number;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
    
     
}
